﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class CourseStudent3
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            pg.Type = "CourseStudent3";
            pg.Title = "学员";                       
            pg.SMenuId = "JX02";        
            pg.Condition = "";
            pg.TableName = "cu_customers";
            pg.KeyFieldName = "id";       
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);            
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            pg.Sop.ADD = pg.Sop.EDIT = pg.Sop.DEL = false;
            DataRow drUser = BasePage.GetUser(session);
            String leagueId = Fun.cString(drUser["LeagueId"]);


            String button = "<a href=\"javascript:ShowModalUrl('popEdit', '../Main/ManagerLay?type=SelectCourse&cid=[id]', '选课程', '', '', '') \"  class='layui-btn layui-btn-xs'>选课程</a>"
                + "<a href=\"javascript:ShowModalUrl('popEdit', '../Main/ManagerLay?type=SelectedCourse&cid=[id]', '已选课程', '', '', '') \"  class='layui-btn layui-btn-xs'>已选课程</a>";

            //本加盟商，同时排除已加入分类的人员
            pg.Sql = String.Format(@"select t1.*,datediff(m,BirdDate,getdate()) custMonth,'' link
from cu_customers t1
inner join (
	select distinct Cid from cu_Contract
	left join 
	cu_Contract_Class on cu_Contract_Class.id=cu_Contract.SetmealId
	where (
	(IsClassHour=0 and  isnull(CourseEnd,'2099-12-31')>GETDATE()) or 
	(IsClassHour=1 and  isnull(CourseEnd,'2099-12-31')>GETDATE() and  isnull(SurplusNumber,0)-isnull(GiveCourseNumber,0)>0)
	) 
	and  status in (1,2,3,4) and cu_Contract.state='2'
) t2 on t1.id=t2.cid
where leagueId={0} ", leagueId);
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custName"; cl.HeadText = "宝宝姓名"; cl.IsCondition = true; cl.ConditionPosition = 1; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Decimal; cl.FieldName = "custMonth"; cl.HeadText = "月龄";  pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "linkName"; cl.HeadText = "家长姓名"; cl.IsCondition = true; cl.ConditionPosition = 1; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.DataType = Tag.Text; cl.FieldName = "custTel"; cl.HeadText = "联系电话"; cl.IsCondition = true; cl.ConditionPosition = 1; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; cl.Script = button; pg.AddColumn(cl);
            return pg;
        }
    }
}